﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BubbleSurvival
{
    /// <summary>
    /// Egy egyszerű sprite
    /// </summary>
    public class Sprite
    {

        protected Texture2D textureImage;           // megjelenő textúra
        protected Vector2 positionValue;            // pozíció
        protected Point frameSize;                  // méret (téglalap)
        protected Vector2 originValue;              // origin (a pontos illesztések és a forgatás miatt középre)
        int collisionOffset;                        // a téglalapos ütköztetés során, a levett méret
        const int defaultCollisionOffset = 10;      // az alapértelmezett
        protected Color color;                      // megjelenítési szín
        protected Color defaultColor = Color.White; // alapértelmezett szín

        /// <summary>
        /// Szín.
        /// </summary>
        public Color Color
        {
            get { return color; }
            set { color = value; }
        }

        /// <summary>
        /// Pozíció.
        /// </summary>
        public Vector2 Position
        {
            set { positionValue = value; }
            get { return positionValue; }
        }

        // Konstruktor 1
        public Sprite(Texture2D textureImage, Vector2 position, Point frameSize)
        {
            this.textureImage = textureImage;
            this.positionValue = position;
            this.frameSize = frameSize;
            this.color = defaultColor;
            this.collisionOffset = defaultCollisionOffset;
            this.originValue = new Vector2(this.frameSize.X / 2, this.frameSize.Y / 2);
        }

        // Konstruktor 2
        public Sprite(Texture2D textureImage, Vector2 position, Point frameSize, Color color)
        {
            this.textureImage = textureImage;
            this.positionValue = position;
            this.frameSize = frameSize;
            this.color = color;
            this.collisionOffset = defaultCollisionOffset;
            this.originValue = new Vector2(this.frameSize.X / 2, this.frameSize.Y / 2);
        }

        // Konstruktor 3
        public Sprite(Texture2D textureImage, Vector2 position, Point frameSize, int collisionOfset)
        {
            this.textureImage = textureImage;
            this.positionValue = position;
            this.frameSize = frameSize;
            this.color = defaultColor;
            this.collisionOffset = collisionOfset;
            this.originValue = new Vector2(this.frameSize.X / 2, this.frameSize.Y / 2);
        }

        // Konstruktor 4
        public Sprite(Texture2D textureImage, Vector2 position, Point frameSize, int collisionOfset, Color color)
        {
            this.textureImage = textureImage;
            this.positionValue = position;
            this.frameSize = frameSize;
            this.color = color;
            this.collisionOffset = collisionOfset;
            this.originValue = new Vector2(this.frameSize.X / 2, this.frameSize.Y / 2);
        }

        /// <summary>
        /// Update.
        /// </summary>
        public virtual void Update(GameTime gameTime)
        { }

        /// <summary>
        /// Draw.
        /// </summary>
        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            // kirajzolás
            spriteBatch.Draw(
                textureImage,
                positionValue,
                null,
                color,
                0,
                originValue,
                1,
                SpriteEffects.None,
                0.1f);
        }

        /// <summary>
        /// Dispose.
        /// </summary>
        public virtual void Dispose()
        {
            textureImage.Dispose();
        }

        // Collosion 1 - téglalapos ütköztetés
        public Rectangle collisionRect
        {
            get
            {
                // egyszerű téglalap
                return new Rectangle(
                    (int)(positionValue.X - frameSize.X / 2 + collisionOffset),
                    (int)(positionValue.Y - frameSize.X / 2 + collisionOffset),
                    (int)(frameSize.X - collisionOffset),
                    (int)(frameSize.Y - collisionOffset));
            }
        }

        // Collosion 2 - körös ütköztetés
        public Circle collosionCircle
        {
            get
            {
                // kör
                return new Circle(positionValue, (frameSize.X - collisionOffset) / 2);
            }
        }

    }
}